class Location < ActiveRecord::Base
  
  has_many :users
  has_many :places
  
  validates_presence_of :full_address
  
  
  
  def self.set_location loc
    if ((city_geo = GeoKit::Geocoders::GoogleGeocoder.geocode(loc[:full_address])) and city_geo.lat) 
      unless (l = Location.find(:first, :conditions => ["full_address = ?", city_geo.full_address ]))
        l = Location.new(:lat => city_geo.lat, :lng => city_geo.lng, :full_address => city_geo.full_address, 
                              :country_code => city_geo.country_code, :state => city_geo.state, :town => city_geo.town, 
                              :province => city_geo.province, :city => city_geo.city, :country => city_geo.country, 
                              :street_address => city_geo.street_address)        
      end
      l          
    else nil
    end
  end
  
end
